var url = 'http://173.224.119.177:8120/stream';
var my_media = null;
var mediaTimer = null;


function playMedia() {
    // Create Media object from src
    my_media = new Media(url, onSuccess, onError);

    // Play audio
    my_media.play();

    // Update my_media position every second
    if (mediaTimer == null) {
        mediaTimer = setInterval(function() {
            // get my_media position
            my_media.getCurrentPosition(
                // success callback
                function(position) {
                    if (position > -1) {
                        setAudioPosition((position) + " sec");
                    }
                },
                // error callback
                function(e) {
                    console.log("Error getting pos=" + e);
                    setAudioPosition("Error: " + e);
                }
            );
        }, 1000);
    }
}

function onSuccess() {
    console.log("playMedia():Audio Success");
}

function onError(error) {
    console.log('code: '    + error.code    + '\n' + 
          'message: ' + error.message + '\n'+ error);
}

function stopMedia() {
    if (my_media) {
        my_media.stop();
    }
    clearInterval(mediaTimer);
    mediaTimer = null;
}


// Set audio position
// 
function setAudioPosition(position) {
    //document.getElementById('audio_position').value = position;
	$('#audio_position').html(position);
}